import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.ArrayList;


/**
 * 
 * @author Devin Wolanick
 * @Version 1.0
 * 
 * Watcher collects data from entire program.
 */
public class Watcher {
	
	private ArrayList<CountingSystem> mySystems = new ArrayList<CountingSystem>();
	private ArrayList<ArrayList<Integer>> countDraw = new ArrayList<ArrayList<Integer>>();
	
	/**
	 * Set up ArrayList
	 */
	public Watcher() {
		mySystems.add(new HiLoSystem());
		mySystems.add(new HiOpISystem());
		mySystems.add(new HiOpIISystem());
		mySystems.add(new ZenSystem());
		mySystems.add(new OmegaIISystem());
		mySystems.add(new KOSystem());
		mySystems.add(new WizardA5System());
	}
	
	/**
	 * Runs all processes on Card
	 * @param aCard The Card
	 */
	public void takeCard (Card aCard) {
		
		ArrayList<Integer> myList = new ArrayList<Integer>();
		myList.add(mySystems.get(0).getCount());
		myList.add(aCard.getNumber());
		this.countDraw.add(myList);
		
		for (int i=0; i<mySystems.size(); i++)
			mySystems.get(i).takeCard(aCard);
	}
	
	/**
	 * Returns HiLo Count
	 * @return HiLo Count
	 */
	public int[] getCounts() {
		int[] countValues = new int[7];
		for (int i=0; i<mySystems.size(); i++)
			countValues[i] = mySystems.get(i).getCount();
		return countValues;
	}
	
	/**
	 * Resets All Counts
	 */
	public void resetAll() {
		for (int i=0; i<mySystems.size(); i++)
			mySystems.get(i).resetCount();
	}
	
	/**
	 * Exports Data
	 */
	public void exportData() {
		try{
		    // Create file 
		    FileWriter fstream = new FileWriter("countdraw.lgr");
		        BufferedWriter out = new BufferedWriter(fstream);
		    for (int i=0; i<countDraw.size(); i++)
		    	out.write(countDraw.get(i).get(0)+"|"+countDraw.get(i).get(1)+"%");
		    //Close the output stream
		    out.close();
		    }catch (Exception e){//Catch exception if any
		      System.err.println("Error: " + e.getMessage());
	    }
	}
}
